package org.fatmansoft.teach.controllers;


import org.fatmansoft.teach.payload.request.DataRequest;
import org.fatmansoft.teach.payload.response.DataResponse;
import org.fatmansoft.teach.service.HomeWorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.imageio.IIOException;
import javax.validation.Valid;
import java.io.IOException;

@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/api/home-work")
public class HomeWorkController {
    @Autowired
    HomeWorkService homeWorkService;

    //布置作业
    @PostMapping("/assignHomeWork")
    public DataResponse assignHomeWork(@Valid@RequestBody DataRequest dataRequest) {
        return homeWorkService.assignHomeWork(dataRequest);
    }
    //删除布置的作业
    @PostMapping("/deleteHomeWork")
    public DataResponse deleteHomeWork(@Valid@RequestBody DataRequest dataRequest) {
        return homeWorkService.deleteHomeWork(dataRequest);
    }

    //教师查询已经布置的作业
    @PostMapping("/findHomeWork")
    public DataResponse findHomeWork(@Valid @RequestBody DataRequest dataRequest) {
        return homeWorkService.findHomeWork(dataRequest);
    }
    //教师查询完成情况
    @PostMapping("/findStudentHomeWork")
    public DataResponse findStudentHomeWork(@Valid @RequestBody DataRequest dataRequest) {
        return homeWorkService.findStudentHomeWork(dataRequest);
    }
    //教师下载作业
    @PostMapping("/downloadHomeWork")
    public DataResponse downloadHomeWork(@Valid @RequestBody DataRequest dataRequest) throws IOException {
      return   homeWorkService.downloadHomeWork(dataRequest);
    }

    //教师为作业打分
    @PostMapping("/setHomeWorkScore")
    public DataResponse setHomeWorkScore(@Valid @RequestBody DataRequest dataRequest) {
        return homeWorkService.setHomeWorkScore(dataRequest);
    }

    //学生提交作业
    @PostMapping("/handInHomeWork")
    public DataResponse handInHomeWork(@Valid @RequestBody DataRequest dataRequest) throws IOException {
        return homeWorkService.setHomeWorkState(dataRequest);
    }
    //学生查询所有作业
    @PostMapping("/findHomeWorkList")
    public DataResponse findHomeWorkList(@Valid @RequestBody DataRequest dataRequest) {
         return homeWorkService.getHomeWorkList(dataRequest);
    }

}
